<html>
<head><meta charset="utf-8"><title>Unpin safety · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html">Unpin safety</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196960417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196960417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196960417">(May 08 2020 at 23:06)</a>:</h4>
<p>Why is Unpin a safe trait? Wouldn't it follow <code>Sync</code>, etc in requiring an unsafe manual impl?</p>



<a name="196961003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196961003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196961003">(May 08 2020 at 23:17)</a>:</h4>
<p>AIUI, it's because there's no inherent unsafety in saying "something special happens when you pin me" -- specifically, the unsafety is gained when someone then invokes <code>Pin::new_unchecked</code> (which they must do because you are Pin).</p>
<p>I am not sure myself if we made the right call or not here -- but it does make sense at a fundamental perspective</p>



<a name="196961089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196961089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196961089">(May 08 2020 at 23:18)</a>:</h4>
<p>Specifically, note that implementing Unpin only stops code from working, it doesn't itself allow any safe code to do more</p>



<a name="196961099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196961099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196961099">(May 08 2020 at 23:18)</a>:</h4>
<p>er, rather, <em>not</em> implementing unpin</p>



<a name="196963757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196963757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196963757">(May 09 2020 at 00:11)</a>:</h4>
<p>Isn't that backwards though? The someone can use <code>Pin::new</code> rather than <code>Pin::unchecked</code> since you <em>aren't</em> pin via the safe manual Unpin impl</p>



<a name="196966228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196966228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196966228">(May 09 2020 at 01:09)</a>:</h4>
<p>Pinning isn't implicitly transitive. Pinning a structure doesn't automatically pin its fields. If you ever pinned a !Unpin field, you'd need unsafe code, meaning you'd have to uphold the invariants of the Pin. That's why, I believe, Unpin is a safe trait. (You therefore, could never pin a !Unpin field of an Unpin struct, as its valid to move the original struct, which would move the field, even if the struct was originally Pinned)</p>



<a name="196987936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/196987936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#196987936">(May 09 2020 at 11:49)</a>:</h4>
<p>Ah ok yeah that makes sense. You can't write a future that needs to be pinned without using unsafe internally anyway</p>



<a name="197416314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Unpin%20safety/near/197416314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Unpin.20safety.html#197416314">(May 13 2020 at 13:59)</a>:</h4>
<p>another major reason for it being safe to implement is that <code>impl Drop for X</code> gives you the same power and was already safe</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>